package com.fs.common.sms.vo;

import com.fs.common.sms.enums.PassagewayEnum;
import com.fs.common.sms.vo.response.AliyunResponse;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @desc 返回消息通知实体类
 * @author ACE
 */
@Data
@Slf4j
public class SendResponse {
	/**
	 * 结果码
	 */
	public String code;
	/**
	 * 消息编号,匹配状态报告时会用到
	 */
	public String msgId;
	/**
	 * 消息结果
	 */
	public String msg;
	/**
	 * 发送回执
	 */
	public String response; 
	/**
	 * 发送是否成功
	 */
	public Boolean success = false;
	/**
	 *  通道标识
	 */
	public PassagewayEnum way;

	public SendResponse() {
	}

	public SendResponse(String code, String msg, Boolean success){
		this.code = code;
		this.msg = msg;
		this.success = success;
	}
	
	public static Map<String, String> codeData = new HashMap<String, String>();
	
	public static SendResponse parser(String response, PassagewayEnum passageway){
		log.info("-"+ passageway.getText() + "-SendResponse :"+ response);
		SendResponse result = null;
		if(response==null){
			return result = new SendResponse("-1","请求无响应",false);
		}else if("119".equals(response)) {
			return result = new SendResponse("119","重复提交错误",false);
		}else {
			String way = passageway.getValue();
			log.info("response is :" + response);
			log.info("way is:" + way);

			if (way.equals(PassagewayEnum.ALIBABA.value)){
				result = new AliyunResponse(response);
			}
		}
		return result;
	}
}
